package view;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.*;

import util.resources.ResourceManager;

public class ScriptEditor extends JFrame {

	private static final long serialVersionUID = 1L;
	private JTextArea content;
	private JScrollPane contentScroller;
	
	public ScriptEditor(String title, ViewController vcontroller) {
		ResourceManager resources = ResourceManager.getInstance();
		resources.addResourcesFromFile("windowProperties");
		
		setTitle(title);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		int[] windowSize = resources.getIntegerArray("scriptEditWindowSize");
		setPreferredSize(new Dimension(windowSize[0], windowSize[1]));
		
		// Create Menu
		setJMenuBar(MenuBar.createMenuBar(resources, resources.getStringArray("EditorBar"), vcontroller));
		
		content = new JTextArea(20, 20);
		content.setLineWrap(true);
		content.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
		
		contentScroller = new JScrollPane(content);
		contentScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		
		JPanel contentPanel = new JPanel();
		contentPanel.setLayout(new GridLayout());
		contentPanel.add(contentScroller);
		this.setContentPane(contentPanel);

		this.pack();
		this.setVisible(true);
	}
	
	public void setContents (String fileContent) {
		content.setText(fileContent);
	}
	
	public String getContents() {
		return content.getText();
	}

}
